package com.nf;

import com.sun.org.apache.regexp.internal.RE;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConnectionHelper {
    private static final String URL="jdbc:mysql://localhost:3306/demo?serverTimezone=UTC";
    private static final String USER="root";
    private static final String PWD="root";

    static {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            throw new RuntimeException("失败："+e.getMessage());
        }
    }

    public static Connection getConn(){
        try {
            return DriverManager.getConnection(URL,USER,PWD);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return null;
    }

    public static void main(String[] args) {
        System.out.println(ConnectionHelper.getConn());
    }
}
